Tux utility

The Tux Utility

Linux distributions have many possible package managers used to install software on a Linux computer. The program Tux - Universal Package Manager Wrapper is designed to provide a universal API to make program installation easy regardless of the distribution.

You can find Tux at https://gitlab.com/silvernode/tux.git, copywrite Copyright (c) 2015, silvernode

There is nothing wrong with the Tux program or the choice to write it in Ruby. However, it is fun to see how this program could look like in Euphoria.

Trying to translate a program from another language line by line to Euphoria is not the way to proceed.

  • I do not program in Ruby
  • You do not end up with idomatic Euphoria
  • If you think of "translation" instead of "program logic" then your program may not work.

Package Manager Database

A incomplete list (to save typing) using a nested sequence format:

export sequence managers = {                                     --  1 
                                                                 --  2 
{ "dnf", -- fedoraBased                                          --  3 
  {"dnf install",                                                --  4 
   "dnf reinstall",                                              --  5 
   "dnf search",                                                 --  6 
   "dnf upgrade",                                                --  7 
   "dnf --refresh check-update",                                 --  8 
   "dnf --refresh upgrade",                                      --  9 
   "dnf --refresh check-update",                                 -- 10 
   "dnf remove",                                                 -- 11 
   "dnf remove",                                                 -- 12 
   "dnf autoremove",                                             -- 13 
   "dnf check-update"                                            -- 14 
  }                                                              -- 15 
},                                                               -- 16 
                                                                 -- 17 
    -- add more as needed                                        -- 18 
                                                                 -- 19 
{ "apt-get",                                                     -- 20 
    { "apt install",                                             -- 21 
      "apt install --reinstall",                                 -- 22 
      "apt search",                                              -- 23 
      "apt upgrade",                                             -- 24 
      "apt update",                                              -- 25 
      "apt update; sudo apt upgrade",                            -- 26 
      "apt  update",                                             -- 27 
      "apt  remove",                                             -- 28 
      "apt remove --purge",                                      -- 29 
      "apt autoremove"                                           -- 30 
    }                                                            -- 31 
},                                                               -- 32 
                                                                 -- 33 
{ "equo", -- saybayon                                            -- 34 
    { "equo i",                                                  -- 35 
     "equo i",                                                   -- 36 
    "equo s",                                                    -- 37 
    "equo u",                                                    -- 38 
    "equo up",                                                   -- 39 
    "equo up && sudo equo u",                                    -- 40 
    "equo update --force",                                       -- 41 
    "equo rm",                                                   -- 42 
    "equo rm --norecursive",                                     -- 43 
    "equo cleanup"                                               -- 44 
    }                                                            -- 45 
},            -- all items followed by , if you use $ end marker -- 46 
                                                                 -- 47 
$ }                                                              -- 48 

Notes

1
to make an identifier "visible" to an including program you must export it
global is used rarely and public is used to make a chain of includes
3
there are no rules for using sequences, arrange data in any convient form
comments using -- can be added anywhere in source-code
48
the $ marker is optional, but make it easy to add items to a sequence list

Which Manager is Installed?

This code is copied from the "New and having problems" thread. Thanks to mollusk and irv.

-- which.e                                              --  1 
                                                        --  2 
include std/filesys.e                                   --  3 
include std/io.e                                        --  4 
                                                        --  5 
include PkgMgrs.e                                       --  6 
                                                        --  7 
export function which()                                 --  8 
                                                        --  9 
    for i=1 to length( managers ) do                    -- 10 
        sequence pkmgr =  locate_file( managers[i][1] ) -- 11 
        if file_type( pkmgr ) = 1 then                  -- 12 
            return i                                    -- 13 
        end if                                          -- 14 
    end for                                             -- 15 
                                                        -- 16 
    return 0                                            -- 17 
end function                                            -- 18 
                                                        -- 19 

6
the database of package managers is imported to make the sequence managers visible
12
a check to make sure that the identifier is a file and not a directory

Tux

include std/sequence.e --> provides join                                                --  1 
include PkgMgrs.e      --> database created for Tux                                     --  2 
include which.e        --> utility created for Tux                                      --  3 
                                                                                        --  4 
integer mgr_index = which()                                                             --  5 
    if mgr_index = 0 then                                                               --  6 
        printf(1, "can not locate a package manager!\n" )                               --  7 
    else                                                                                --  8 
        printf(1, "pkg manager is : %s\n\n", { managers[ mgr_index ][1]} )              --  9 
    end if                                                                              -- 10 
                                                                                        -- 11 
sequence options = {                                                                    -- 12 
{ "Install a package", "i", "add", "get", "S", "install" },                             -- 13 
{ "Reinstall a package", "ri", "ri", "reinstall" },                                     -- 14 
{ "Remove a package", "r", "R", "rm", "remove", "delete" },                             -- 15 
{ "Force remove a package", "rf", "Rdd", "force-remove" },                              -- 16 
{ "Remove orphan packages", "c", "clean" },                                             -- 17 
{ "Search remote repository", "s", "se", "Ss", "search", "find" },                      -- 18 
{ "Sync local and remote repo", "sy", "Sy", "sync", "refresh" },                        -- 19 
{ "Upgrade packages on the system", "u", "up", "u", "Su", "upgrade"},                   -- 20 
{ "Sync mirror and upgrade system", "su", "Syu", "sup", "syncup" },                     -- 21 
{ "Show current version", "v", "version"  }                                             -- 22 
}                                                                                       -- 23 
                                                                                        -- 24 
procedure Usage()                                                                       -- 25 
    printf(1, "Tux Usage: tux [options] [argument]\n\n" )                               -- 26 
    for i=1 to length(options) do                                                       -- 27 
        printf(1, "%-31s: %s\n", { options[i][1], join( options[i][2..$], ", " ) } )    -- 28 
    end for                                                                             -- 29 
    abort(0) -- terminate the program                                                   -- 30 
end procedure                                                                           -- 31 
                                                                                        -- 32 
                                                                                        -- 33 
sequence cmd = command_line()                                                           -- 34 
                                                                                        -- 35 
atom option_index = 0                                                                   -- 36 
                                                                                        -- 37 
if length(cmd) < 3 then                                                                 -- 38 
    Usage()                                                                             -- 39 
    -- only items three and up are user entries                                         -- 40 
else                                                                                    -- 41 
    -- identify the option                                                              -- 42 
    sequence option = cmd[3]                                                            -- 43 
                                                                                        -- 44 
        for i=1 to length(options) do                                                   -- 45 
            if find( option, options[i][2..$] ) then                                    -- 46 
                option_index = i                                                        -- 47 
                printf(1, "\nselected option is : " & option & "\n")                    -- 48 
                exit                                                                    -- 49 
            end if                                                                      -- 50 
        end for                                                                         -- 51 
                                                                                        -- 52 
    -- identify the argument                                                            -- 53 
    if valid_index( cmd, 4 ) then                                                       -- 54 
        printf(1, "using argument: %s\n", { cmd[4] } )                                  -- 55 
    else                                                                                -- 56 
        cmd = append(cmd, "" )                                                          -- 57 
    end if                                                                              -- 58 
                                                                                        -- 59 
                                                                                        -- 60 
end if                                                                                  -- 61 
                                                                                        -- 62 
sequence action                                                                         -- 63 
if option_index = 0 then                                                                -- 64 
    Usage()                                                                             -- 65 
else                                                                                    -- 66 
    action = managers[mgr_index][2][option_index] & " " & cmd[4]                        -- 67 
end if                                                                                  -- 68 
                                                                                        -- 69 
printf(1, "you have chosen to: %s\n\n", { action } )                                    -- 70 
                                                                                        -- 71 
printf(1, "type    * control c to abort,\n        * enter admin password to proceed\n") -- 72 
                                                                                        -- 73 
system( "sudo " & action )                                                              -- 74                                                                 -- 67 

2
to use the sequence managers we need to include for every file wanting access
6
as variables are needed we declare the data-type
some authors will make a list of all variables at the head of a program
undeclared variables result in an error
6
zero mean false, and not zero means true (there is no NIL in Euphoria)
9
notice that managers[ mgr_index ][1] must be enclosed by {}, else you only get one character printed
12
I chose to split the help file into words
this lets me both output a help message and use the items in searching for options
26
traditionaly, procedures and functions are defined at the top of a program, Euphoria allows them to be defined in any location and they will still be in scope
you can not nest routines inside other routines
27
Euphoria does not use ranges in loops, everything is done with an integer index
28
printf, is copied from 'c' syntax and seems to be common to many languages
30
abort is used to kill a program
38
command_line always returns at least two items, items three (and greater) are user input
45
this is were I use the info in the "help" file to search for an option
54
if the user does not enter a fourth item, I create an empty place-holder
67
the managers database now gives us the packagemanger and its options-argumnents that should be executed

This is not a replacement for Tux written in Ruby. This Euphoria version is just the first step in building a replacement.

_tom

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu